package org.agent.action;

import java.util.Date;
import java.util.List;

import org.agent.common.Constants;
import org.agent.pojo.Role;
import org.agent.service.role.RoleService;

public class RoleAction extends BaseAction {
		
	//拿到service
	private RoleService roleService;
	
	private Role role;
	private List<Role> roleList;//查询列表
	private String type;//通过这个值判断新增还是修改
	
	
	//查询所有角色
	public String roleList(){
	roleList =	this.getRoleService().getRoleList();
		return SUCCESS;
	}
	//编辑
	public String editRole(){
		System.out.println("进入edit");
		
		if (type.equals("add")) {
			//添加
			//System.out.println(role.getRoleName());
			role.setCreationTime(new Date());
			role.setLastUpdateTime(new Date());
			role.setCreatedBy(this.getCurrentUser().getUserCode());
			if(this.getRoleService().addRole(role)>0){
				this.getOut().print("success");
			}else {
				this.getOut().print("faild");
			}
			
			
		}else if(type.equals("modify")) {
			
			role.setLastUpdateTime(new Date());
			//System.out.println("进入modify");
			System.out.println(role.getId());
			if(this.getRoleService().modifyRole(role)>0){
				this.getOut().print("success");
			}else{
				this.getOut().print("faild");
			}
			
		}
		return null;
	}
	
	
	//删除
	public String deleteRole(){
		System.out.println("进入deleteRoleAction");
		System.out.println("++++++++++++"+role.getId());
		if(this.getRoleService().deleteRole(role)>0){
			this.getOut().print("success");
		}else{
			this.getOut().print("faild");
		}
		return null;
}
	
	
	public RoleService getRoleService() {
		return roleService;
	}
	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	public List<Role> getRoleList() {
		return roleList;
	}
	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
}
